/**
  ** 用于系统管理，例如后台检测安全
  ** 对异常信息进行调度
**/
#ifndef APPMANAGER_H
#define APPMANAGER_H

#include "MU_API.h"
#include "src/define/func_define.h"
#include "TaskManager.h"
#include <QScopedPointer>
#include <mutex>
#include <QMutex>
#include <QScopedPointer>
#include <boost/signals2.hpp>
#include "src/DataProvider/App/SysMembers.h"

class AppManager
{
public:
    AppManager();
    static AppManager* GetInstance(){
        static QMutex mutex;
        static QScopedPointer<AppManager> inst;
        if (Q_UNLIKELY(!inst)) {
            mutex.lock();
            if (!inst) {
                inst.reset(new AppManager);
            }
            mutex.unlock();
        }
        return inst.data();
    }

    /// 打印异常代码
    static void showErrorMessage(MU_E_TYPE &msg);

public:
    TaskManager task;


     boost::signals2::signal<void(std::string)> reportExp;
     boost::signals2::signal<void(std::string)> reportWarn;
private:
    /// 异常处理线程
    void initThread();
    /// 处理异常
    void handlerError();

    void handlerWarn();

    /// 当前指针
    /// 0:检查线程，用于实时检查异常信息
    /// 1:Task线程,用于启动或者停止Task
    QScopedPointer<std::thread> _workService[4];

    std::recursive_mutex _mtx;
    std::atomic<bool> allowRead = ATOMIC_FLAG_INIT;



};

#endif // APPMANAGER_H
